//
//  UTString+Date.swift
//  iPhoneTests
//
//  Created by Toj on 8/9/22.
//

import XCTest

class UTString_Date: XCTestCase {
    
    override func setUpWithError() throws {
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDownWithError() throws {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
    }
    
    func testExample() throws {
        print("-->UTests: start \n")
        
        // testStringToDate()
        // testToSeconds2()
        // testStringDateSeries()
        
        print("-->UTests: end \n")
    }
    
    func testPerformanceExample() throws {
        // This is an example of a performance test case.
        self.measure {
            // Put the code you want to measure the time of here.
        }
    }
}

extension UTString_Date {
    
    func testToSeconds2() {
        var seconds = "".to_seconds
        seconds = "10:00:10:00".to_seconds
        print("-->UTests: value: \(seconds)")
    }
    
    func testToSeconds() {
        var seconds = "".to_seconds
        // 正常值
        seconds = "00:00:00".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "00:00:01".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "00:00:1".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "0:1:1".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "1:0:1".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "1:1:1".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "00:1:0".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "1:1:0".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "1:0:0".to_seconds
        print("-->UTests: value: \(seconds)")
        
        // 边界值
        seconds = "0:0:0".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "0:0:59".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "0:59:0".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "23:0:0".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "23:59:59".to_seconds
        print("-->UTests: value: \(seconds)")
        
        // 特殊值
        seconds = "".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "::".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "0:70:60".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "0:60:0".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "34:0:0".to_seconds
        print("-->UTests: value: \(seconds)")
        
        // 无效值
        seconds = "A:B:C".to_seconds
        print("-->UTests: value: \(seconds)")
        
        seconds = "0:0:-1".to_seconds
        print("-->UTests: value: \(seconds)")
    }
}

extension UTString_Date {
    
    func testStringDateSeries() {
        var series = ""
        
        // MARK: - 参考: 2023-11-10 10:00:00
        let formatter = DateFormatter()
        let date = Date(timeIntervalSince1970: 1699581600)
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        let dateString = formatter.string(from: date)
        print("-->UTests: to_dateSeries: current -> \(dateString)")
        
        
        // MARK: - 跨年: yyyy-MM-dd [1年, ~)
        // MARK: - 相差 (1年, ~)
        // MARK: 今年: 2021-08-13 23:44:53
        series = 1628869493.to_dateSeries
        print("-->UTests: to_dateSeries: 2021-08-13 23:44:53 -> \(series)")
        // MARK: 今年: 2020-12-03 12:23:41
        series = 1606969421.to_dateSeries
        print("-->UTests: to_dateSeries: 2020-12-03 12:23:41 -> \(series)")
        // MARK: 今年: 2011-08-12 13:45:56
        series = 1313127956.to_dateSeries
        print("-->UTests: to_dateSeries: 2011-08-12 13:45:56 -> \(series)")
        
        // MARK: - 相差 1年 多1秒
        // MARK: 跨年: 2022-11-10 09:59:59
        series = 1668045599.to_dateSeries
        print("-->UTests: to_dateSeries: 2022-11-10 09:59:59 -> \(series)")
        // MARK: - 相差 1年
        // MARK: 跨年: 2022-11-10 10:00:00
        series = 1668045600.to_dateSeries
        print("-->UTests: to_dateSeries: 2022-11-10 10:00:00 -> \(series)")
        
        
        // MARK: - 今年: MM-dd [1天, 1年)
        // 参考: 2023-11-10 10:00:00
        
        // MARK: - 相差 1年 少1秒
        // MARK: 今年: 2022-11-10 10:00:01
        series = 1668045601.to_dateSeries
        print("-->UTests: to_dateSeries: 2022-11-10 10:00:01 -> \(series)")
        
        // MARK: - 相差 (1天, 1年)
        // MARK: 今年: 2023-02-10 08:34:57
        series = 1675989297.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-02-10 08:34:57 -> \(series)")
        // MARK: 今年: 2023-08-04 11:32:11
        series = 1691119931.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-08-04 11:32:11 -> \(series)")
        // MARK: 今年: 2022-12-08 23:45:32
        series = 1670514332.to_dateSeries
        print("-->UTests: to_dateSeries: 2022-12-08 23:45:32 -> \(series)")
        
        // MARK: - 相差 1天 1秒
        // MARK: 今年: 2023-11-09 09:59:59
        series = 1699495199.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-09 09:59:59 -> \(series)")
        // MARK: - 相差 1天
        // MARK: 今年: 2023-11-09 10:00:00
        series = 1699495200.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-09 10:00:00 -> \(series)")
        
        
        // MARK: - 今日 HH:mm(24小时制) [30分, 1天)
        // 参考: 2023-11-10 10:00:00
        
        // MARK: - 相差 1天 少1秒
        // MARK: 今日: 2023-11-09 10:00:01
        series = 1699495201.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-09 10:00:01 -> \(series)")
        
        // MARK: - 相差 (30分, 1天)
        // MARK: 今日: 2023-11-09 23:07:34
        series = 1699542454.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-09 23:07:34 -> \(series)")
        // MARK: 今日: 2023-11-09 16:14:08
        series = 1699517648.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-09 16:14:08 -> \(series)")
        // MARK: 今日: 2023-11-10 08:34:57
        series = 1699576497.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 08:34:57 -> \(series)")
        
        // MARK: - 相差 30分 1秒
        // MARK: 今日: 2023-11-10 09:29:59
        series = 1699579799.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:29:59 -> \(series)")
        // MARK: - 相差 30分
        // MARK: 今日: 2023-11-10 09:30:00
        series = 1699579800.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:30:00 -> \(series)")
        
        
        // MARK: - 刚刚 [0秒, 30分)
        // 参考: 2023-11-10 10:00:00
        
        // MARK: - 相差 29分 59秒
        // MARK: 刚刚: 2023-11-10 09:30:01
        series = 1699579801.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:30:01 -> \(series)")
        
        // MARK: - 相差 (1秒, 30分)
        // MARK: 刚刚: 2023-11-10 09:30:35
        series = 1699579835.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:30:35 -> \(series)")
        // MARK: 刚刚: 2023-11-10 09:40:08
        series = 1699580408.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:40:08 -> \(series)")
        // MARK: 刚刚: 2023-11-10 09:50:46
        series = 1699581046.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:50:46 -> \(series)")
        
        // MARK: - 相差 1秒
        // MARK: 刚刚: 2023-11-10 09:59:59
        series = 1699581599.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:59:59 -> \(series)")
        // MARK: - 相差 0秒
        // MARK: 刚刚: 2023-11-10 10:00:00
        series = 1699581600.to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 10:00:00 -> \(series)")
    }
    
    func testStringDateStringSeries() {
        var series = ""
        
        // MARK: - 参考: 2023-11-10 10:00:00
        let formatter = DateFormatter()
        let date = Date(timeIntervalSince1970: 1699581600)
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        let dateString = formatter.string(from: date)
        print("-->UTests: to_dateSeries: current -> \(dateString)")
        
        
        // MARK: - 跨年: yyyy-MM-dd [1年, ~)
        // MARK: - 相差 (1年, ~)
        // MARK: 今年:
        series = "2021-08-13 23:44:53".to_dateSeries
        print("-->UTests: to_dateSeries: 2021-08-13 23:44:53 -> \(series)")
        // MARK: 今年: 2020-12-03 12:23:41
        series = "2020-12-03 12:23:41".to_dateSeries
        print("-->UTests: to_dateSeries: 2020-12-03 12:23:41 -> \(series)")
        // MARK: 今年: 2011-08-12 13:45:56
        series = "2011-08-12 13:45:56".to_dateSeries
        print("-->UTests: to_dateSeries: 2011-08-12 13:45:56 -> \(series)")
        
        // MARK: - 相差 1年 多1秒
        // MARK: 跨年: 2022-11-10 09:59:59
        series = "2022-11-10 09:59:59".to_dateSeries
        print("-->UTests: to_dateSeries: 2022-11-10 09:59:59 -> \(series)")
        // MARK: - 相差 1年
        // MARK: 跨年: 2022-11-10 10:00:00
        series = "2022-11-10 10:00:00".to_dateSeries
        print("-->UTests: to_dateSeries: 2022-11-10 10:00:00 -> \(series)")
        
        
        // MARK: - 今年: MM-dd [1天, 1年)
        // 参考: 2023-11-10 10:00:00
        
        // MARK: - 相差 1年 少1秒
        // MARK: 今年: 2022-11-10 10:00:01
        series = "2022-11-10 10:00:01".to_dateSeries
        print("-->UTests: to_dateSeries: 2022-11-10 10:00:01 -> \(series)")
        
        // MARK: - 相差 (1天, 1年)
        // MARK: 今年: 2023-02-10 08:34:57
        series = "2023-02-10 08:34:57".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-02-10 08:34:57 -> \(series)")
        // MARK: 今年: 2023-08-04 11:32:11
        series = "2023-08-04 11:32:11".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-08-04 11:32:11 -> \(series)")
        // MARK: 今年: 2022-12-08 23:45:32
        series = "2022-12-08 23:45:32".to_dateSeries
        print("-->UTests: to_dateSeries: 2022-12-08 23:45:32 -> \(series)")
        
        // MARK: - 相差 1天 1秒
        // MARK: 今年: 2023-11-09 09:59:59
        series = "2023-11-09 09:59:59".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-09 09:59:59 -> \(series)")
        // MARK: - 相差 1天
        // MARK: 今年: 2023-11-09 10:00:00
        series = "2023-11-09 10:00:00".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-09 10:00:00 -> \(series)")
        
        
        // MARK: - 今日 HH:mm(24小时制) [30分, 1天)
        // 参考: 2023-11-10 10:00:00
        
        // MARK: - 相差 1天 少1秒
        // MARK: 今日: 2023-11-09 10:00:01
        series = "2023-11-09 10:00:01".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-09 10:00:01 -> \(series)")
        
        // MARK: - 相差 (30分, 1天)
        // MARK: 今日: 2023-11-09 23:07:34
        series = "2023-11-09 23:07:34".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-09 23:07:34 -> \(series)")
        // MARK: 今日: 2023-11-09 16:14:08
        series = "2023-11-09 16:14:08".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-09 16:14:08 -> \(series)")
        // MARK: 今日: 2023-11-10 08:34:57
        series = "2023-11-10 08:34:57".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 08:34:57 -> \(series)")
        
        // MARK: - 相差 30分 1秒
        // MARK: 今日: 2023-11-10 09:29:59
        series = "2023-11-10 09:29:59".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:29:59 -> \(series)")
        // MARK: - 相差 30分
        // MARK: 今日: 2023-11-10 09:30:00
        series = "2023-11-10 09:30:00".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:30:00 -> \(series)")
        
        
        // MARK: - 刚刚 [0秒, 30分)
        // 参考: 2023-11-10 10:00:00
        
        // MARK: - 相差 29分 59秒
        // MARK: 刚刚: 2023-11-10 09:30:01
        series = "2023-11-10 09:30:01".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:30:01 -> \(series)")
        
        // MARK: - 相差 (1秒, 30分)
        // MARK: 刚刚: 2023-11-10 09:30:35
        series = "2023-11-10 09:30:35".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:30:35 -> \(series)")
        // MARK: 刚刚: 2023-11-10 09:40:08
        series = "2023-11-10 09:40:08".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:40:08 -> \(series)")
        // MARK: 刚刚: 2023-11-10 09:50:46
        series = "2023-11-10 09:50:46".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:50:46 -> \(series)")
        
        // MARK: - 相差 1秒
        // MARK: 刚刚: 2023-11-10 09:59:59
        series = "2023-11-10 09:59:59".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 09:59:59 -> \(series)")
        // MARK: - 相差 0秒
        // MARK: 刚刚: 2023-11-10 10:00:00
        series = "2023-11-10 10:00:00".to_dateSeries
        print("-->UTests: to_dateSeries: 2023-11-10 10:00:00 -> \(series)")
    }
}
